package com.cloudkinto.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 资源映射配置
 *
 * @author long
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Value("${gbc.uploadPath.filePathLocal}")
    private String filePathLocal;

    /*@Value("${gbc.uploadPath.filePath}")
    private String filePathLinux;*/

    /**
     * 配置本地资源映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String filePath = "";
        String os = System.getProperty("os.name").toLowerCase();
        /*if (os.startsWith("linux")) {
            //服务器配置
            filePath = filePathLinux;
        } else */if (os.startsWith("win")) {
            //本地测试配置
            filePath = "file:" + filePathLocal;
        }

        //资源请求路径
        registry.addResourceHandler("/upload/**")
                .addResourceLocations(filePath);
    }
}
